package com.situ.mall.controller.back;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.common.ServerResponse;
import com.situ.mall.entity.Category;
import com.situ.mall.service.ICategoryService;
import com.situ.mall.service.impl.CategoryServiceImpl;

@Controller
@RequestMapping(value="/category")
public class CategoryController {
	@Autowired
	private ICategoryService categoryService;
	
	//网页查看用户管理
	@RequestMapping(value="/getCategoryPage")
	public String getCategoryPage() {
		return "category/category_list";
	}
	
	//分页数据，默认查找totalcount，layui表格自动添加分页信息：page,limit 
	@RequestMapping(value="/pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page,Integer limit,Category category,Date time){
		System.out.println(time);
		System.out.println(category.getStatus());
		
		ServerResponse serverResponse = categoryService.pageList(page, limit,category);
		System.out.println(serverResponse);
		return serverResponse;
	}
	
	//Id删除
	@RequestMapping(value="/deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id) {
		return categoryService.deleteById(id);
	}
	
	//批量删除
	@RequestMapping(value="/deleteAll")
	@ResponseBody
	public ServerResponse deleteAll(String ids) {
		return categoryService.deleteAll(ids);
	}
	
	//添加页面商品分类一级标题
	@RequestMapping(value="/selectTopCategory")
	@ResponseBody
	public ServerResponse selectTopCategory(Model model) {
		return categoryService.selectTopCategory();
	}
	
	//添加页面商品分类二级标题，这里的topCategoryId就是一级标题的主键
	@RequestMapping(value="/selectSecondCategory")
	@ResponseBody
	public ServerResponse selectSecondCategory(Integer topCategoryId) {
		return categoryService.selectSecondCategory(topCategoryId);
	}
	
	//添加一级分类页面
	@RequestMapping(value="/getAddPage")
	public String getAddPage() {
		return "category/category_addone";
	}
	
	//添加一级分类功能
	@RequestMapping(value="/insert")
	@ResponseBody
	public ServerResponse insert(Category category) {
		return categoryService.insert(category);
	}
	
	//添加二级分类页面
	@RequestMapping(value="/getAddPage2")
	public String getAddPage2() {
		return "category/category_addtwo";
	}
	
	//添加二级分类功能
	@RequestMapping(value="/insert2")
	@ResponseBody
	public ServerResponse insert2(Category category) {
		System.out.println(category);
		return categoryService.insert2(category);
	}
	
	//修改一级分类页面
	@RequestMapping(value="/getUpdatePage1")
	public String getUpdatePage1(Integer id,Model model) {
		Category category = categoryService.toUpdate(id);
		model.addAttribute("category",category);
		return "category/category_update1";
	}
	
	//修改一级分类功能
	@RequestMapping(value="/update1")
	@ResponseBody
	public ServerResponse update1(Category category) {
		return categoryService.update(category);
	}
	
	//修改二级分类页面
	@RequestMapping(value="/getUpdatePage2")
	public String getUpdatePage2(Integer id,Model model) {
		Category category = categoryService.toUpdate(id);
		model.addAttribute("category",category);
		return "category/category_update2";
	}
	
	//修改二级分类功能
	@RequestMapping(value="/update2")
	@ResponseBody
	public ServerResponse update2(Category category) {
		return categoryService.update(category);
	}
	
	//----------------------------------echarts商品数量统计Start
	//得到统计页面
	@RequestMapping(value="/getCategoryCountPage")
	public String getCategoryCountPage() {
		return "category/category_count";
	}
	
	//拿到统计数据
	@RequestMapping(value="/getCategoryCount")
	@ResponseBody
	public ServerResponse getCategoryCount() {
		return categoryService.selectCategoryCount();
	}
	//----------------------------------echarts商品数量统计End
	
	
	
}
